package pl.enigmatic.math;

public class RangeFloat {

	private float left = 0;
	private boolean closedLeft = true;
	private float right = 1;
	private boolean closedRight = true;

	public RangeFloat(boolean closedLeft, float left, float right, boolean closedRight) {
		this.left = left;
		this.closedLeft = closedLeft;
		this.right = right;
		this.closedRight = closedRight;
	}

	public float getLeft() {
		return left;
	}

	public void setLeft(final float left) {
		this.left = left;
	}

	public boolean isClosedLeft() {
		return closedLeft;
	}

	public void setClosedLeft(final boolean closedLeft) {
		this.closedLeft = closedLeft;
	}

	public float getRight() {
		return right;
	}

	public void setRight(final float right) {
		this.right = right;
	}

	public boolean isClosedRight() {
		return closedRight;
	}

	public void setClosedRight(final boolean closedRight) {
		this.closedRight = closedRight;
	}

	public boolean isInside(final float x) {
		return (left < x || closedLeft && left == x) && (x < right || closedRight && right == x);
	}

	public boolean isOutside(final float x) {
		return !isInside(x);
	}

	public boolean isEmpty() {
		return left < right || left == right && closedLeft && closedRight;
	}

	public float getLength() {
		return right - left;
	}
}
